package com.jf.hotelreservation.demos.controller;

import com.alibaba.fastjson2.JSON;
import com.jf.hotelreservation.demos.utils.AliOSSUpload;
import com.jf.hotelreservation.demos.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;



@RestController
public class UploadController {

    @Autowired
    private AliOSSUpload aliOSSUpload;

    @PostMapping("/upload")
    public String upload(@RequestBody MultipartFile file) throws Exception {
        String imgPath = aliOSSUpload.uploadFile(file);
        if (imgPath != null){
            return JSON.toJSONString(R.success("上传成功" , imgPath));
        }else {
            return JSON.toJSONString(R.error("上传失败"));
        }

    }
}
